package examples.camera.command
{
	import flash.display.BitmapData;
	import flash.events.TimerEvent;
	import flash.filters.BlurFilter;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import flash.utils.Timer;

	import org.seasar.akabana.yui.command.AsyncCommand;

	public class CameraAsyncResizeCommand extends AsyncCommand
	{
		private var t:Timer = new Timer(1000);

		public function CameraAsyncResizeCommand()
		{
			super();
		}


		private var bmpData:BitmapData;
		protected override function runAsync():void {
			bmpData = _arguments[0] as BitmapData;

			var rect:Rectangle = new Rectangle(10, 10,
				bmpData.width / 2 , bmpData.height / 2);
			bmpData.fillRect(rect, 0xFF0000);

			var pt:Point = new Point(10, 10);
			var filter:BlurFilter = new BlurFilter();
			bmpData.applyFilter(bmpData, rect, pt, filter);

			t.addEventListener(TimerEvent.TIMER, onTimer);
			t.start();
		}

		private function onTimer(event:TimerEvent):void {
			t.stop();
			t.removeEventListener(TimerEvent.TIMER_COMPLETE, onTimer);
			returnAsync(bmpData);
		}
	}
}